package com.s.core.root.data;

import com.s.core.root.D;
import com.s.core.root.strategy.base.FeatureContainer;

import java.util.*;

public abstract class _BasePic extends FeatureContainer {

    public _BasePic(_AllData allData, D d, int loadMax) {
        this.allData = allData;
        this.d = d;
        List<D> dList = d.bDailyList(loadMax);
        init(dList, null);
    }

    public _BasePic(_AllData allData, D d, int loadMax, Object initParams) {
        this.allData = allData;
        this.d = d;
        List<D> dList = d.bDailyList(loadMax);
        init(dList, initParams);
    }

    public _AllData allData;
    public D d;

    public abstract void init(List<D> dList, Object initParams);

    public abstract List<? extends _BasePoint> getPointList();

    private final Map<List<? extends _BasePoint>, Long> maxVolMap = new HashMap<>();

    public long getMaxVol() {
        List<? extends _BasePoint> points = getPointList();
        if (!maxVolMap.containsKey(points)) {
            maxVolMap.put(points, getMaxVol(points));
        }
        return maxVolMap.get(points);
    }

    private long getMaxVol(List<? extends _BasePoint> points) {
        Optional<? extends _BasePoint> maxYcCoordinate = points.stream().filter(point -> !point.isTp()).
                max((o1, o2) -> (int) (o1.vol().longValue() - o2.vol().longValue()));
        return maxYcCoordinate.map(t -> t.vol().longValue()).orElse(0L);
    }
}
